import { IPos } from "../common/Common";
import { Fview, UILayer, View } from "../gui/UIDefine";


export interface itmeSign {
    sign: string;
}

/**
 * 坐标格式化
 * @param p 转换坐标
 * @param parent 父级，默认特效层
 * @returns 
 */
export function getPos(p: IPos, parent: Fview | Laya.Sprite = Laya.stage): IPos {


    if (p instanceof Laya.Sprite || p instanceof View) {
        let sp = p instanceof Laya.Sprite ? p : p.displayListContainer;
        let spParent = parent instanceof Laya.Sprite ? parent : parent.displayListContainer;
        let pos = sp.localToGlobal(Laya.Point.TEMP.setTo(p.width >> 1, p.height >> 1));
        spParent.globalToLocal(pos);
        let temp = { x: pos.x, y: pos.y };
        return temp;
    }

    return { x: p.x, y: p.y };
}

/**
 * 计算距离
 * @param x 
 * @param y 
 * @returns 
 */
export function distance(x: IPos, y: IPos) {
    let a = getPos(x), b = getPos(y);
    return Math.sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}

//金币坐标
export function goldPo(): IPos {
    return { x: 100, y: 100 };
}

